package com.kaishengit.util;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import javax.inject.Named;

import org.springframework.web.multipart.MultipartFile;

/**
 * 文件存储的工具类
 * @author wuzhixuan
 *
 */
@Named
public class UpLoadFile {

    public String uploadFile(String savedDir,MultipartFile file) throws IOException {
    	if(!file.isEmpty()){   
            //以下的代码是将文件file重新命名存入自己配置的路径
            String fileRealName = file.getOriginalFilename();                   //获得原始文件名;  
            
            //获取服务器指定文件存取路径    
            File savedFile = new File(savedDir,fileRealName );  
            boolean isCreateSuccess = savedFile.createNewFile();  
            if(isCreateSuccess){                      
                file.transferTo(savedFile);  //转存文件  
            }  
            return "success";    
     }  
     return "error";  
 
    }
    
    
    
       
}

